<template>
  <div>
    <div class="header-btn">
      <div>新增模板</div>
      <div>
        <el-button type="primary">确认</el-button>
        <el-button type="info" plain @click="$router.back()">返回</el-button>
      </div>
    </div>
    <div class="wrap g-card" style="margin-bottom: 20px">
      <div class="title-header">基础设置</div>
      <el-form ref="form" :model="form" :rules="rules" label-width="100px" label-position="right"
        style="position: relative">
        <el-form-item label="模板名称名称" prop="taskName">
          <div>哈哈哈哈</div>

          <el-input v-show="false" v-model="form.taskName" popper-class="minWidth-inp" style="width: 600px"
            placeholder="请输入">
          </el-input>
          <div></div>
        </el-form-item>
        <el-form-item label="文本">
          <el-input type="textarea" :autosize="{ minRows: 3 }" placeholder="请填写文本内容" v-model="form.remark"
            style="width: 600px" maxlength="640" show-word-limit>
          </el-input>
          <!-- <div v-show="formDetail">{{ form.remark }}</div> -->
        </el-form-item>
        <el-form-item label="发送内容">
          <div class="block-wrap">
            <div class="block-item" @click="textDialog = true">
              <svg-icon icon-class="text" />
              <div>文本</div>
            </div>
            <div class="block-item">
              <svg-icon icon-class="customPicture" />
              <div>自定义图片</div>
            </div>
            <div class="block-item">
              <svg-icon icon-class="h5link" />
              <div>h5链接</div>
            </div>
            <div class="block-item">
              <svg-icon icon-class="poster" />
              <div>海报</div>
            </div>
            <div class="block-item">
              <svg-icon icon-class="article" />
              <div>文章</div>
            </div>
            <div class="block-item">
              <svg-icon icon-class="file" />
              <div>文件</div>
            </div>
            <div class="block-item">
              <svg-icon icon-class="insurance" />
              <div>险种</div>
            </div>
            <div class="block-item">
              <svg-icon icon-class="LocalLibrary" />
              <div>本地库</div>
            </div>
          </div>
          <div style="color: #999" v-if="form.scrmPersonSopMaterials.length > 0">
            (添加的多个内容可一键发送，最多可发10条)
          </div>
          <template v-if="form.scrmPersonSopMaterials.length > 0">
            <div class="upload-list" v-for="(item, index) in form.scrmPersonSopMaterials" :key="index">
              <div>
                <span v-if="item.text">文本: {{ item.text }}</span>
                <span v-if="item.materialUrl">海报: {{ item.materialName }}</span>

                <span style="margin-left: 10px;color: coral;" @click="uploadMerge(index)">详情</span>
                <span style="margin-left: 10px ;color: coral;" @click="uploadDelete(index)">删除</span>
                <!-- <span @click="uploadDetail">详情</span> -->

              </div>

            </div>
          </template>
        </el-form-item>
        <el-form-item label="二维码">
          <NormalQrCode :codeInfo="codeParams" @selectedSure="qrCodeConfrim" @deleteSeletedQrcode="deleteSeletedQrcode" />
        </el-form-item>
      </el-form>
    </div>
    <!-- 文案-上传文本 -->
    <text-upload :textDialog="textDialog" @close="closeText" :textUpload="textUpload"></text-upload>

  </div>
</template>

<script>
import { textUpload, sourceMaterial } from "../personalSop/component/index";

export default {
  name: "HandleMessage",
  data() {
    return {
      textDialog: false,//文本输入
      textUpload: "", // 点击修改，赋值文本内容
      form: {
        // 基础设置
        taskName: "", // 任务名称
        scrmPersonSopMaterials: [], // 素材
        radio1: '有二维码',
        chooseStaff: "1",
        remark: "",
        pageNum: 1,
        pageSize: 10,
      },
      rules: {
        title: [
          { required: true, message: "请输入文案内容", trigger: "change" },
        ],
      },
      operateFlag: '',
      codeParams: {
        qrState: '1',
        qrType: '',
        activityName: '',
        codeUrl: '',
        qrId: ''
      },
    };
  },
  components: { textUpload, sourceMaterial },
  methods: {
    // 删除二维码
    deleteSeletedQrcode() {
      this.codeParams.qrType = '';
      this.codeParams.activityName = '';
      this.codeParams.codeUrl = '';
      this.codeParams.qrId = '';
    },
    qrCodeConfrim(data) {
      if (data) {
        this.codeParams = {
          qrState: data.qrState,
          qrType: data.qrType,
          activityName: data.activityName,
          codeUrl: data.qrCode || data.codeUrl,
          qrId: data.qrId
        }
      } else {
        this.codeParams = {
          qrState: 1,
          qrType: '',
          activityName: '',
          codeUrl: '',
          qrId: ''
        }
      }
    },
    // 修改
    uploadMerge(index) {
      this.textDialog = true;
      this.textIndex = index;
      this.textUpload = this.form.scrmPersonSopMaterials[index].text;
    },
    // 删除
    uploadDelete(index) {
      this.form.scrmPersonSopMaterials.splice(index, 1);
    },
    // 选择文本
    closeText(text) {
      this.textDialog = false;
      if (text) {
        // 新增
        if (!this.textUpload) {
          this.form.scrmPersonSopMaterials.push({
            text: text,
          });
        } else {
          // 修改
          this.form.scrmPersonSopMaterials[this.textIndex].text = text;
        }
      }
      // this.uploadList = [...this.from.sendContent];
    },
  },
};
</script>

<style lang="scss" scoped>
@import "../../../styles/base.scss";

.header-btn {
  @include headerBtn;
}

.wrap {
  @include titleWrap;
}

.dialog-wrap {
  display: flex;
  justify-content: flex-start;

  .dialog-list {
    width: 33%;
    padding: 0 15px;
    box-sizing: border-box;
    max-height: 500px;
    overflow: auto;

    &:nth-child(2) {
      flex: 1;
      border-left: $normalBorder;
      border-right: $normalBorder;
    }
  }

  .block-wrap {
    display: flex;
    justify-content: flex-start;
    flex-wrap: wrap;
    font-weight: 600;
    color: #2a2a2a;
    font-size: 12px;
    font-family: PingFangSC-Medium, PingFang SC;

    .block-item {
      width: 80px;
      padding: 5px 0;
      margin: 10px;
      border: $normalBorder;
      text-align: center;

      .svg-icon {
        width: 4em;
        height: 3em;
        vertical-align: -0.15em;
        fill: currentColor;
        overflow: hidden;
      }
    }
  }

  .upload-list {
    display: flex;
    justify-content: space-between;
    border: $normalBorder;
    padding: 0 10px;
  }
}

.copy-card {
  width: 740px;
  background-color: #fafafa;
  position: relative;
  margin: 10px;

  .content-item {
    width: 400px;
    background-color: #e9e9e9;
    padding: 0 10px;
    margin-bottom: 10px;
    display: flex;
    justify-content: space-between;
  }

  .copy-edit {
    position: absolute;
    top: 20px;
    right: 20px;
  }

  .right-close {
    position: absolute;
    right: -2px;
    top: -2px;
  }
}

.group {
  position: relative;
  margin-top: 5px;
  width: 180px;
  height: 60px;
  border: 1px solid #082aff;
  color: #082aff;
  border-radius: 6px;
  padding-left: 5px;

  .two {
    margin-top: -5px;
  }

  .el-icon-error {
    position: absolute;
    right: -5px;
    top: -7px;
    font-size: 20px;
  }
}

.seleteGroup {
  ::v-deep .el-dialog__header {
    background: #eeeeee;
    color: #2A2A2A;
  }
}

.tableGroup {
  height: 40px !important;
  padding-left: 10px;
}

.block-wrap {
  display: flex;
  justify-content: flex-start;
  flex-wrap: wrap;
  font-weight: 400;
  color: #2a2a2a;
  font-size: 12px;
  font-family: PingFangSC-Medium, PingFang SC;

  .block-item {
    width: 80px;
    padding: 5px 0;
    margin: 10px;
    border: $normalBorder;
    text-align: center;

    .svg-icon {
      width: 4em;
      height: 3em;
      vertical-align: -0.15em;
      fill: currentColor;
      overflow: hidden;
      margin-top: 12px;
    }

    div {
      margin-top: -10px;
    }
  }

  .upload-list {
    display: flex;
    justify-content: space-between;
    border: $normalBorder;
    padding: 0 10px;
  }
}
</style>
